function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val)
    this.next = (next === undefined ? null : next)
}
var removeNthFromEnd = function (head, n) {
    let dummyHead = new ListNode(0, head);
    let fast = slow = dummyHead;
    while (n--) { fast = fast.next; }
    while (fast.next) {
        fast = fast.next;
        slow = slow.next;
    }
    slow.next = slow.next.next;
    console.log(dummyHead.next);
    return dummyHead.next;
};
const a1 = new ListNode(1);
const a2 = new ListNode(2);
const a3 = new ListNode(3);
const a4 = new ListNode(4);
const a5 = new ListNode(5);

a1.next = a2;
a2.next = a3;
a3.next = a4;
a4.next = a5;

removeNthFromEnd(a1, 4);